<template>
  <div class="tags">
    <el-tag
      v-for="(item, index) in tabsList"
      :key="item.path"
      :closable="item.label != '首页'"
      :effect="$route.name === item.name ? 'dark' : 'plain'"
      @click="changMenu(item)"
      @close="closeMenu(item.name, index)"
      size="mini"
    >
      {{ item.label }}
    </el-tag>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  name: "CommonTage",
  computed: {
    ...mapState("tabs", ["tabsList"]),
  },
  methods: {
    ...mapMutations("tabs", ["delMenu"]),

    changMenu(value) {
      this.$router.push({
        name: value.name,
      });
    },
    closeMenu(value, index) {
      const length = this.tabsList.length - 1;
      this.delMenu(value);
      if (length === index) {
        this.$router.push({
          name: this.tabsList[index - 1].name,
        });
      }
      if (this.$route.name === value){
          this.$router.push({
          name: this.tabsList[index].name,
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.tags {
  margin-bottom: 10px;
  .el-tag {
    margin-right: 5px;
    &:hover {
      cursor: pointer;
    }
  }
}
</style>